﻿using System;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;

namespace HPSocketLibrary
{
    public static class ConsoleHelper
    {
        public delegate void WriteLogEventHandler(Run run);

        public static event WriteLogEventHandler writeLogHandler;

        public static void Info(string text)
        {
            Application.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                Run run = new Run() { Text = DateTime.Now.ToString("HH:mm:ss") + " > " + text + "\n", Foreground = Brushes.DeepSkyBlue };
                writeLogHandler?.Invoke(run);
            }));
        }

        public static void Success(string text)
        {
            Application.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                Run run = new Run() { Text = DateTime.Now.ToString("HH:mm:ss") + " > " + text + "\n", Foreground = Brushes.LightGreen };
                writeLogHandler?.Invoke(run);
            }));
        }

        public static void Error(string text)
        {
            Application.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                Run run = new Run() { Text = DateTime.Now.ToString("HH:mm:ss") + " > " + text + "\n", Foreground = Brushes.Red };
                writeLogHandler?.Invoke(run);
            }));
        }
        public static void Warn(string text)
        {
            Application.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                Run run = new Run() { Text = DateTime.Now.ToString("HH:mm:ss") + " > " + text + "\n", Foreground = Brushes.Yellow };
                writeLogHandler?.Invoke(run);
            }));
        }
        public static void Color(string text, SolidColorBrush colorBrush)
        {
            Application.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                Run run = new Run() { Text = DateTime.Now.ToString("HH:mm:ss") + " > " + text + "\n", Foreground = colorBrush };
                writeLogHandler?.Invoke(run);
            }));
        }
    }
}
